//
//  Extension+Color.swift
//  ZDKBaseKit
//
//  Created by Killua on 2017/9/22.
//  Copyright © 2017年 JingZhong. All rights reserved.
//

import UIKit

extension UIColor {
    
    /// 根据十六进制值返回透明度为1的颜色
    ///
    /// - Parameter hex: 十六制作色值
    /// - Returns: UIColor
    class func hexColor(hex: Int) -> UIColor {
        return UIColor.hexColor(hex: hex, alpha: 1)
    }

    /// 根据十六进制值及透明度返回颜色
    ///
    /// - Parameters:
    ///   - hex: 十六制作色值
    ///   - alpha: 颜色透明度
    /// - Returns: UIColor
    class func hexColor(hex: Int, alpha: CGFloat) -> UIColor {
        let red = CGFloat((hex & 0xFF0000) >> 16) / 255
        let green = CGFloat((hex & 0xFF00) >> 8) / 255
        let blue = CGFloat(hex & 0xFF) / 255
        return UIColor.init(red: red, green: green, blue: blue, alpha: alpha)
    }

    /// 根据RGBA设置颜色
    ///
    /// - Parameters:
    ///   - red: 红
    ///   - green: 绿
    ///   - blue: 蓝
    ///   - alpha: 透明度
    /// - Returns: UIColor
    class func color(_ red: CGFloat, _ green: CGFloat, _ blue: CGFloat, _ alpha: CGFloat) -> UIColor {
        return UIColor.init(red: red/255.0, green: green/255.0, blue: blue/255.0, alpha: alpha);
    }

    /// 根据RGB设置颜色
    ///
    /// - Parameters:
    ///   - red: 红
    ///   - green: 绿
    ///   - blue: 蓝
    /// - Returns: UIColor
    class func color(_ red: CGFloat, _ green: CGFloat, _ blue: CGFloat) -> UIColor {
        return color(red, green, blue, 1);
    }
}
